﻿<MForm>
    <MContainer>
        <MRow>
            <MCol Cols="12">
                <MTextField @bind-Value="_message"
                            AppendIcon="@(_marker ? "mdi-map-marker" : "mdi-map-marker-off")"
                            AppendOuterIcon="@(!string.IsNullOrEmpty(_message) ? "mdi-send" : "mdi-microphone")"
                            PrependIcon="@Icon"
                            Filled
                            ClearIcon="mdi-close-circle"
                            Clearable
                            Label="Message"
                            Type="text"
                            OnAppendClick="ToggleMarker"
                            OnAppendOuterClick="SendMessage"
                            OnClearClick="ClearMessage"
                            OnPrependClick="ChangeIcon">
                </MTextField>
            </MCol>
        </MRow>
    </MContainer>
</MForm>

@code {
    private string _message = "Hey!";
    private bool _marker = true;

    private List<string> _icons = new List<string>
    {
        "mdi-emoticon",
        "mdi-emoticon-cool",
        "mdi-emoticon-dead",
        "mdi-emoticon-excited",
        "mdi-emoticon-happy",
        "mdi-emoticon-neutral",
        "mdi-emoticon-sad",
        "mdi-emoticon-tongue",
    };

    private int _iconIndex = 0;

    public string Icon => _icons[_iconIndex];

    public void ToggleMarker()
    {
        _marker = !_marker;
    }

    public void ChangeIcon()
    {
        if (_iconIndex == _icons.Count - 1)
        {
            _iconIndex = 0;
        }
        else
        {
            _iconIndex++;
        }
    }

    public void SendMessage()
    {
        _iconIndex = 0;
        _message = "";
    }

    public void ClearMessage()
    {
        _message = "";
    }

}